using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Elvex
{
    public static class CameraUtility
    {
        public static Texture2D Capture(this Camera camera)
        {
            RenderTexture rt = new RenderTexture(Screen.width, Screen.height, 16);
            camera.targetTexture = rt;
            camera.Render();
            RenderTexture.active = rt;
            Texture2D t = new Texture2D(Screen.width, Screen.height);
            t.ReadPixels(new Rect(0, 0, t.width, t.height), 0, 0);
            t.Apply();
            camera.targetTexture = null;
            return t;
        }
    }

}
